//
//  UWONavigationControllerViewController.m
//  basic
//
//  Created by Jack on 2016/12/13.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "UWONavigationController.h"

@interface UWONavigationController ()

@end

@implementation UWONavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationBar.barTintColor = UWORGB_COLOR(0, 126, 259);
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count >= 1) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        [viewController.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
        
        // 将控制器中的返回按钮进行统一设置
        viewController.navigationItem.backBarButtonItem = [self addBarItemWithImage:@"back" WithHighImage:@"back" WithTagetAction:@selector(backClick) WithTarger:self];
    }
    [super pushViewController:viewController animated:YES];
}

#pragma mark navigationItem按钮点击事件
- (void)backClick {
    [self popViewControllerAnimated:YES];
}

- (UIBarButtonItem *)addBarItemWithImage:(NSString *)imageName WithHighImage:(NSString *)hightImage WithTagetAction:(SEL)action WithTarger:(id)target{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:hightImage] forState:UIControlStateHighlighted];
    
    CGRect btnRect = CGRectZero;
    btnRect.size = CGSizeMake(30, 30);
    button.frame = btnRect;
    
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
    return item;
}


@end
